package com.cssy.yd.basic.dao.impl;

import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.cssy.yd.basic.dao.BasicPlaceofstorageDAO;
import com.cssy.yd.basic.entity.BasicPlaceofstorageDO;
import com.plat.helper.SearchConditions;

/**
 * 数据访问对象实现类
 * @since 2013-04-24
 */
public class BasicPlaceofstorageDAOImpl extends SqlMapClientDaoSupport implements BasicPlaceofstorageDAO {

    /**
     * 插入数据
     * @param basicPlaceofstorageDO
     * @return 插入数据的主键
     */
    public String insertBasicPlaceofstorageDO(BasicPlaceofstorageDO basicPlaceofstorageDO) throws DataAccessException {
        Object id = getSqlMapClientTemplate().insert("BasicPlaceofstorage.insert", basicPlaceofstorageDO);
        return (String) id;
    }

    /**
     * 统计记录数
     * @param basicPlaceofstorageDO
     * @return 查出的记录数
     */
    public Integer countBasicPlaceofstorageDOByExample(BasicPlaceofstorageDO basicPlaceofstorageDO) throws DataAccessException {
        Integer count = (Integer) getSqlMapClientTemplate().queryForObject("BasicPlaceofstorage.countByDOExample", basicPlaceofstorageDO);
        return count;
    }

    /**
     * 更新记录
     * @param basicPlaceofstorageDO
     * @return 受影响的行数
     */
    public Integer updateBasicPlaceofstorageDO(BasicPlaceofstorageDO basicPlaceofstorageDO) throws DataAccessException {
        int result = getSqlMapClientTemplate().update("BasicPlaceofstorage.update", basicPlaceofstorageDO);
        return result;
    }

    /**
     * 获取对象列表
     * @param basicPlaceofstorageDO
     * @return 对象列表
     */
    @SuppressWarnings("unchecked")
    public List<BasicPlaceofstorageDO> findListByExample(BasicPlaceofstorageDO basicPlaceofstorageDO) throws DataAccessException {
        List<BasicPlaceofstorageDO> list = getSqlMapClientTemplate().queryForList("BasicPlaceofstorage.findListByDO", basicPlaceofstorageDO);
        return list;
    }

    /**
     * 根据主键获取basicPlaceofstorageDO
     * @param id
     * @return basicPlaceofstorageDO
     */
    public BasicPlaceofstorageDO findBasicPlaceofstorageDOByPrimaryKey(String id) throws DataAccessException {
        BasicPlaceofstorageDO basicPlaceofstorageDO = (BasicPlaceofstorageDO) getSqlMapClientTemplate().queryForObject("BasicPlaceofstorage.findByPrimaryKey", id);
        return basicPlaceofstorageDO;
    }

    /**
     * 删除记录
     * @param id
     * @return 受影响的行数
     */
    public Integer deleteBasicPlaceofstorageDOByPrimaryKey(String id) throws DataAccessException {
        Integer rows = (Integer) getSqlMapClientTemplate().delete("BasicPlaceofstorage_ex.deleteById", id);
        return rows;
    }

    @Override
   	public List<BasicPlaceofstorageDO> find(SearchConditions scs)
   			throws DataAccessException {
   		System.out.println(scs.getPrefix());
   		List<BasicPlaceofstorageDO> list = getSqlMapClientTemplate().queryForList("BasicPlaceofstorage_ex.find", scs);
   		   return list;
   	}

   	@Override
   	public Integer count(SearchConditions scs) throws DataAccessException {		
   		 Integer count = (Integer) getSqlMapClientTemplate().queryForObject("BasicPlaceofstorage_ex.count", scs);
   	      return count;
   	}

	@Override
	public boolean validateWhCodeAndHubcode(String whcode, String hubcode)
			throws DataAccessException {
		BasicPlaceofstorageDO basicPlaceofstorageDO=new BasicPlaceofstorageDO();
		basicPlaceofstorageDO.setCode(hubcode);
		basicPlaceofstorageDO.setStorageid(whcode);
		basicPlaceofstorageDO.setRemoved(0);
		List<BasicPlaceofstorageDO> list = getSqlMapClientTemplate().queryForList("BasicPlaceofstorage.findListByDO", basicPlaceofstorageDO);
		if(list.size()>0){
			return true;
		}else{
			return false;
		}
	}
}